package com.goblin.model.uaa.service;

import java.util.List;
import java.util.Optional;

import com.goblin.common.response.PageHelper;
import com.goblin.common.response.Paged;
import com.goblin.model.uaa.po.Menu;
import com.goblin.model.uaa.repository.MenuRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MenuServiceImpl implements MenuService {
	@Autowired
	private MenuRepository menuRepository;

	@Override
	public Paged<Menu> paged(PageHelper pageable) {
		return this.menuRepository.paged(pageable);
	}

	@Override
	public List<Menu> tree() {

		List<Menu> menus = this.menuRepository.findMenusByIsRoot(true);

		return menus;

	}

	@Override
	public Optional<Menu> findByParentId(Integer parentId) {
		return this.menuRepository.findById(parentId);
	}

	@Override
	public void save(Menu menu) {
		this.menuRepository.save(menu);
	}

	@Override
	public List<Menu> all() {
		return this.menuRepository.findAll();
	}

}
